export default {
    mounted() {
        this.getCategory1();
        this.$bus.$on("hander1", this.hander1);
        this.$bus.$on("hander2", this.hander2);
        this.$bus.$on("hander3", this.hander3);
    },
    methods: {
        async getCategory1() {
            let result = await this.$api.default.category.getCategory1();
            if (result.code == 200) {
                this.list1 = result.data;
            }
        },
        async hander1(id1) {
            this.formInfo.category1Id = id1;
            this.formInfo.category2Id = "";
            this.formInfo.category3Id = "";
            this.list2 = [];
            this.list3 = [];
            this.$bus.$emit('setfInfo1');
            let result = await this.$api.default.category.getCategory2By1Id(
                this.formInfo.category1Id
            );
            if (result.code == 200) {
                this.list2 = result.data;
            }
        },
        async hander2(id2) {
            this.formInfo.category2Id = id2;
            this.formInfo.category3Id = "";
            this.list3 = [];
            this.$bus.$emit('setfInfo2');
            let result = await this.$api.default.category.getCategory3By2Id(
                this.formInfo.category2Id
            );
            if (result.code == 200) {
                this.list3 = result.data;
            }
        },
    },
    beforeDestroy() {
        this.$bus.$off(["hander1", "hander2", "hander3"]);
    },
}